package func.study.groovy.dsl

/**
 * Created by yao_pc on 2017/8/4.
 */
class DSLBase {
    static Map map = new HashMap()
    static Site site = new Site()
    public static void main(String[] args) {
        graber{
            site {
                timeout 10000
                retryNum 3
            }
            data {
                set("name") {

                    "zhangsan"
                }
                set("age") {
                    11
                }

            }
        }
        println map

    }

    def static graber(closure) {
        closure()
    }

    def static site(closure) {
        closure()
        map.put("site", site)
    }

    def static data(closure) {
        closure()
    }

    def static set(name, closure) {
        map.put(name, closure())
    }
    def static timeout(ms) {
        site.setTimeout(ms)
    }
    def static retryNum(num) {
        site.setRetryNum(num)
    }

}
class Site {
    def timeout
    def retryNum


    @Override
    public String toString() {
        return "Site{" +
                "timeout=" + timeout +
                ", retryNum=" + retryNum +
                '}';
    }
}
